package com.car.web.Car;

import com.car.domain.Car;
import com.car.server.impl.AdminCarSeverImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/car/amendCar")
public class AmendCar extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //查找car所有内容
        String cid = req.getParameter("cid");
        Car car = new AdminCarSeverImpl().AmendCarServer(cid);
        if (car!=null){
            //正确,
            req.setAttribute("amend",car);
            req.getRequestDispatcher("amendCar.jsp").forward(req,resp);
        }else{
            //出错了
            req.getSession().setAttribute("amend","错误");
            resp.sendRedirect("showMyCar.jsp");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
